<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:v="http://corejsf.com/validator">

    <f:view>
        <f:loadBundle var="text" basename="#{employeeForm.bundleName}"/>
        <head>
            <title>#{text['employeeDetail.title']}</title>
            <meta name="heading" content="#{text['employeeDetail.heading']}"/>
            <meta name="menu" content="AdminMenu"/>
        </head>

        <div class="separator"></div>

        <h:form id="employeeForm">
            <h:inputHidden value="#{employeeForm.employee.id}" id="id"/>

            <c:if test="${employeeForm.rememberMe}">
                <h:inputHidden value="#{employeeForm.user.password}" id="password"/>
                <h:inputHidden value="#{employeeForm.user.confirmPassword}" id="confirmPassword"/>
            </c:if>

            <h:panelGrid columns="3">
                <h:panelGroup styleClass="buttonBar right">
                    <h:commandButton value="#{text['button.save']}" action="#{employeeForm.save}" id="save" styleClass="button"/>
                    <c:if test="${not empty employeeForm.employee.id}">
                        <h:commandButton value="#{text['button.delete']}" action="#{employeeForm.delete}"
                                         id="delete" styleClass="button"/>
                    </c:if>
                    <h:commandButton value="#{text['button.cancel']}" action="cancel" immediate="true"
                                     id="cancel" styleClass="button"/>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup styleClass="info">
                    <c:choose>
                        <c:when test="${param.from == 'list' or empty employeeForm.employee.id}">
                            <h:outputText value="#{text['employeeDetail.admin.message']}"/>
                        </c:when>
                        <c:otherwise><h:outputText value="#{text['employeeDetail.message']}"/></c:otherwise>
                    </c:choose>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="firstName" value="#{text['employee.firstName']}"/>
                            <h:inputText styleClass="text medium" id="firstName" value="#{employeeForm.employee.firstName}" maxlength="100" required="true"/>
                            <t:message for="firstName" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="lastName" value="#{text['employee.lastName']}"/>
                            <h:inputText styleClass="text medium" id="lastName" value="#{employeeForm.employee.lastName}" maxlength="100" required="true"/>
                            <t:message for="lastName" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="homePhone" value="#{text['employee.homePhone']}"/>
                            <h:inputText styleClass="text medium" id="homePhone" value="#{employeeForm.employee.homePhone}"/>
                            <t:message for="homePhone" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="mobilePhone" value="#{text['employee.mobilePhone']}"/>
                            <h:inputText styleClass="text medium" id="mobilePhone" value="#{employeeForm.employee.mobilePhone}"/>
                            <t:message for="mobilePhone" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:outputLabel for="address" value="#{text['employee.address']}" styleClass="desc"/>
                <t:message for="address" styleClass="fieldError"/>
                <h:inputText value="#{employeeForm.employee.address}" id="address" styleClass="text large"/>
                <h:outputText/><h:outputText/>

                <h:outputLabel for="type" value="#{text['employee.type']}" styleClass="desc"/>
                <t:message for="type" styleClass="fieldError"/>
                <h:selectOneMenu value="#{employeeForm.employee.type}" id="type" required="true" styleClass="select">
                    <t:selectItems value="#{employeeForm.employeeTypes}" var="type" itemLabel="#{type.description}" itemValue="#{type}"/>
                    <f:converter converterId="objconverter"/>
                    <v:commonsValidator client="true" type="required" arg="#{text['employee.type']}"/>
                </h:selectOneMenu>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="career" value="#{text['employee.career']}"/>
                            <h:inputText styleClass="text medium" id="career" value="#{employeeForm.employee.career}"/>
                            <t:message for="career" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="occupation" value="#{text['employee.occupation']}"/>
                            <h:inputText styleClass="text medium" id="occupation" value="#{employeeForm.employee.occupation}"/>
                            <t:message for="occupation" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel for="email" value="#{text['employee.email']}" styleClass="desc"/>
                            <t:message for="email" styleClass="fieldError"/>
                            <h:inputText value="#{employeeForm.employee.email}" id="email" styleClass="text medium">
                                <f:validator validatorId="org.apache.myfaces.validator.Email"/>
                                <v:commonsValidator client="true" type="required" arg="#{text['employee.email']}"/>
                                <v:commonsValidator client="true" type="email" arg="#{text['employee.email']}"/>
                            </h:inputText>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="otherPhone" value="#{text['employee.otherPhone']}"/>
                            <h:inputText styleClass="text medium" id="otherPhone" value="#{employeeForm.employee.otherPhone}"/>
                            <t:message for="otherPhone" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:outputLabel for="username" styleClass="desc" value="#{text['user.username']}"/>
                <t:message for="username" styleClass="fieldError"/>
                <h:inputText value="#{employeeForm.user.username}" id="username" required="true" styleClass="text large">
                    <v:commonsValidator client="true" type="required" arg="#{text['user.username']}"/>
                </h:inputText>

                <c:if test="${!employeeForm.rememberMe}">
                    <h:panelGroup>
                        <div>
                            <div class="left">
                                <h:outputLabel for="password" value="#{text['user.password']}" styleClass="desc"/>
                                <t:message for="password" styleClass="fieldError"/>
                                <h:inputSecret value="#{employeeForm.user.password}" id="password"
                                               redisplay="true" required="true" styleClass="text medium">
                                    <v:commonsValidator client="true" type="required" arg="#{text['user.password']}"/>
                                </h:inputSecret>
                            </div>
                            <div>
                                <h:outputLabel for="confirmPassword" value="#{text['user.confirmPassword']}" styleClass="desc"/>
                                <t:message for="confirmPassword" styleClass="fieldError"/>
                                <h:inputSecret value="#{employeeForm.user.confirmPassword}" id="confirmPassword"
                                               redisplay="true" required="true" styleClass="text medium">
                                    <v:commonsValidator client="true" type="required" arg="#{text['user.confirmPassword']}"/>
                                    <t:validateEqual for="password"/>
                                </h:inputSecret>
                            </div>
                        </div>
                    </h:panelGroup>
                    <h:outputText/><h:outputText/>
                </c:if>

                <h:outputLabel for="passwordHint" value="#{text['user.passwordHint']}" styleClass="desc"/>
                <t:message for="passwordHint" styleClass="fieldError"/>
                <h:inputText value="#{employeeForm.user.passwordHint}" id="passwordHint" required="true" styleClass="text large">
                    <v:commonsValidator client="true" type="required" arg="#{text['user.passwordHint']}"/>
                </h:inputText>

                <c:choose>
                    <c:when test="${param.from == 'list' or param['editUser:add'] == addText}">
                        <h:panelGroup>
                            <t:htmlTag value="fieldset">
                                <t:htmlTag value="legend"><h:outputText value="#{text['userProfile.accountSettings']}"/></t:htmlTag>
                                <h:selectBooleanCheckbox value="#{employeeForm.user.enabled}" id="enabled" styleClass="checkbox"/>
                                <h:outputLabel for="enabled" styleClass="choice" value="#{text['user.enabled']}"/>

                                <h:selectBooleanCheckbox value="#{employeeForm.user.accountExpired}" id="accountExpired" styleClass="checkbox"/>
                                <h:outputLabel for="accountExpired" styleClass="choice" value="#{text['user.accountExpired']}"/>

                                <h:selectBooleanCheckbox value="#{employeeForm.user.accountLocked}" id="accountLocked" styleClass="checkbox"/>
                                <h:outputLabel for="accountLocked" styleClass="choice" value="#{text['user.accountLocked']}"/>

                                <h:selectBooleanCheckbox value="#{employeeForm.user.credentialsExpired}" id="credentialsExpired" styleClass="checkbox"/>
                                <h:outputLabel for="credentialsExpired" styleClass="choice" value="#{text['user.credentialsExpired']}"/>
                            </t:htmlTag>
                        </h:panelGroup>
                        <h:outputText/><h:outputText/>
                        <h:panelGroup>
                            <fieldset>
                                <legend>#{text['userProfile.assignRoles']}</legend>
                                <h:selectManyCheckbox value="#{employeeForm.userRoles}" id="userRoles">
                                    <f:selectItems value="#{employeeForm.availableRoles}"/>
                                </h:selectManyCheckbox>
                            </fieldset>
                        </h:panelGroup>
                        <h:outputText/><h:outputText/>
                    </c:when>
                    <c:otherwise>
                        <h:panelGroup>
                            <t:htmlTag value="strong">#{text['user.roles']}:</t:htmlTag>
                            <c:if test="${not empty param['employeeForm:userRoles']}">
                                ${param['employeeForm:userRoles']}
                                <input type="hidden" name="employeeForm:userRoles" value="${param['employeeForm:userRoles']}" />
                            </c:if>
                            <c:forEach var="role" items="#{employeeForm.userRoles}" varStatus="status">
                                ${role}<c:if test="${!status.last}">,</c:if>
                                <input type="hidden" name="employeeForm:userRoles" value="${role}" />
                            </c:forEach>
                            <h:inputHidden value="#{employeeForm.user.enabled}"/>
                            <h:inputHidden value="#{employeeForm.user.accountExpired}"/>
                            <h:inputHidden value="#{employeeForm.user.accountLocked}"/>
                            <h:inputHidden value="#{employeeForm.user.credentialsExpired}"/>
                        </h:panelGroup>
                        <h:outputText/><h:outputText/>
                    </c:otherwise>
                </c:choose>
            </h:panelGrid>
            <t:saveState id="save1" value="#{employeeForm.employee}"/>
            <t:saveState id="save2" value="#{employeeForm.user}"/>
        </h:form>

        <script type="text/javascript">
            Form.focusFirstElement($('employeeForm'));
            highlightFormElements();
        </script>
    </f:view>
</html>